/*
 * 太原学院  20220322
 */
package cn.edu.tyu.finance.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * MySQL数据库实用类
 * @author ljw
 * @version 1.0
 */
public class DbUtil {

	 public static Connection getConnection() {
		 Connection conn = null;
		 String url = "jdbc:mysql://localhost:3306/financedb";
		 try {
			conn = DriverManager.getConnection(url, "root", "root");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		 return conn;
	 }
	 /**
	  * 归返数据库的连接
	  */
	 public static void backConn(Connection conn,PreparedStatement ps,ResultSet rs) {
		 if(rs!=null) {
			 try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
		 if(ps!=null) {
			 try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
		 if(conn!=null) {
			 try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
	 }
		 
}
